<?php include('../../CE/config.php'); ?>
<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN"
"http://www.wapforum.org/DTD/xhtml-mobile10.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Login</title>
    <link type="text/css" rel="Stylesheet" href="../Sites/AppRes/yuicssreset.css" />
	<style type="text/css">
    body { font-size:12px;}
    legend { font-size:14px; margin:10px; font-weight:bold; border-bottom:solid 1px #CCC; padding:10px; width:100%;}
    input { padding:5px;}
    .control-group { clear:left;padding:10px;}
        .control-label { float:left; font-weight:bold; margin-right:10px; }
    </style>
</head>

<body>
<?php 
if($wu->request_string('act')=='login'){
    $data=$db->fetch_row("select Password from tusermember where UserName='".$wu->request_string('UserName')."'");
	if(!$data){ 
		LoginFailFunc('用户名错误');
	}
	if($data['Password']!=$wu->request_string('Password')){
		LoginFailFunc('密码错误');
	}
	$_SESSION['uname']=$wu->request_string('UserName');
	$wu->redirect('登录成功','index.php');
}else{	
	if(!$db->fetch_value("select count(0) from tusermember where UserName='sysadmin'")){
		$db->insert('tusermember','UserName,Password,IsAdmin',"'sysadmin','Aa123456_',1");
	}
}
function LoginFailFunc($msg){
		global $wh;
		$n=isset($_COOKIE['n'])?$_COOKIE['n']:0;
		$n++;
		setcookie('n',$n,time()+180);
		if($n>2){
			die('您已尝试3次，请3分钟后再登录');	
		}else{
			$wu->redirect($msg.',还可以尝试'.(3-$n).'次','?fail');	
		}
}
?>
<form action="#" method="post">
    <h1>用户登录</h1>
    <table>
    	<tr><td>用户名</td><td><input type="text" name="UserName" /></td></tr>
        <tr><td>密码</td><td><input type="password" name="Password" /></td></tr>
        <tr><td colspan="2"><input type="submit" value="登录" /> <input type="reset" class="btn" value="重置" /></td></tr>
    </table>
    <input type="hidden" name="act" value="login" />
    </form>
</body>
</html>
